/*
 * @Author: your name
 * @Date: 2021-12-27 14:24:15
 * @LastEditTime: 2021-12-27 19:46:40
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \gantt-vue2\src\elastic\src\components\Chart\Row\Task.mixin.js
 */
/**
 * @fileoverview Task mixin
 * @license MIT
 * @author Rafal Pospiech <neuronet.io@gmail.com>
 * @package GanttElastic
 */

export default {
    computed: {
        /**
         * Get view box
         *
         * @returns {string}
         */
        getViewBox() {
            const task = this.task
            return `0 0 ${task.width} ${task.height}`
        },

        /**
         * Get group transform
         *
         * @returns {string}
         */
        getGroupTransform() {
            return `translate(${this.task.x} ${this.task.y})`
        },

        /**
         * Should we display expander?
         *
         * @returns {boolean}
         */
        displayExpander() {
            const expander = this.root.state.options.chart.expander
            return (
                expander.display ||
                (expander.displayIfTaskListHidden &&
                    !this.root.state.options.taskList.display)
            )
        },
    },
    methods: {
        /**
         * Emit event
         *
         * @param {string} eventName
         * @param {Event} event
         */
        emitEvent(eventName, event) {
            if (!this.root.state.options.scroll.scrolling) {
                this.root.$emit(`chart-${this.task.type}-${eventName}`, {
                    event,
                    data: this.task,
                })
            }
        },
        handleMouseDown(event) {
            this.root.state.options.nodeMove.task = this.task
            this.root.state.options.nodeMove.moving = true
            this.root.state.options.nodeMove.startClientX = event.clientX
            this.root.state.options.nodeMove.endClientY = event.clientY
            this.root.state.options.nodeMove.oriX = this.task.x
            this.emitEvent("mousedown", event)
        },
        handleMouseMove(event) {
            this.emitEvent("mousemove", event)
        },
        handleResizeMouseDown(event, direction) {
            this.root.state.options.nodeMove.task = this.task
            this.root.state.options.nodeMove.moving = true
            this.root.state.options.nodeMove.startClientX = event.clientX
            this.root.state.options.nodeMove.endClientY = event.clientY
            this.root.state.options.nodeMove.oriX = this.task.x
            this.root.state.options.nodeMove.isResize = true
            this.root.state.options.nodeMove.resizeSize = direction
            this.emitEvent("resizemousedown", event)
        },
    },
}
